package cn.cvs.service.impl;

import cn.cvs.dao.SysRoleMapper;
import cn.cvs.pojo.SysRole;
import cn.cvs.service.SysRoleService;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class SysRoleServiceImpl implements SysRoleService {
    @Resource
    SysRoleMapper sysRoleMapper;
    @Resource
    RedisTemplate redisTemplate;

    @Override
    public List<SysRole> queryAllRoles() {
        Object queryAllRoles = redisTemplate.opsForValue().get("queryAllRoles");
        if (queryAllRoles != null) {
            return (List<SysRole>) queryAllRoles;
        }
        List<SysRole> sysRoles = sysRoleMapper.queryAll();
        if (sysRoles !=null){
            //添加入缓存
            redisTemplate.opsForValue().set("queryAllRoles",sysRoles);
        }
        return sysRoles;
    }
}
